package com.service.Authorization.service.impl;

/**
 * @author
 * @version 1.0
 * @date 2020/11/11 11:11
 */


import com.service.Authorization.config.MailUtil;
import com.service.Authorization.dto.MailBean;
import com.service.config.utils.JsonXMLUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by GK_LZS  ON 2019/4/5
 * 注入消息接受类
 *
 * @author 林泽思
 */

@Service
public class ReceiverRedisMessageServiceImpl {
    private static final Logger log = LoggerFactory.getLogger(ReceiverRedisMessageServiceImpl.class);

    @Resource
    MailUtil mailUtil;





    /**
     * 队列消息接收方法
     *
     * @param jsonMsg
     */
    public void receiveMessage(String jsonMsg) throws Exception {
        log.info("[ begin consumer REDIS  sendEmail data ...]");
        //序列化对象（特别注意：发布的时候需要设置序列化；订阅方也需要设置序列化）
        MailBean mailBean = JsonXMLUtils.json2obj(jsonMsg, MailBean.class);
        try {
            mailUtil.sendSimpleMail(mailBean);
            log.info("[consumer REDIS  sendEmail success ]");
        } catch (Exception e) {
            log.error("[consumer REDIS  sendEmail error ，errorMsg:{}]", e.getMessage());
        }
    }
}
